//
//  UINavigationItemAdditions.m
//  iTravel
//
//  Created by COLD FRONT on 12-6-19.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "UINavigationItemAdditions.h"

@implementation UINavigationItem (Navigation)

+ (UILabel *)titleViewForTitle:(NSString *)title
{
    UILabel *titleView = [[UILabel alloc] init];
    titleView.font = [UIFont fontWithName:@"Helvetica" size:20];
    titleView.backgroundColor = [UIColor clearColor];
    titleView.textColor = [UIColor whiteColor];
    titleView.text = [NSString stringWithFormat:@"%@",title];
    [titleView sizeToFit];
    return titleView;
}

- (void)setLeftBarButtonItem:(UIBarButtonItem *)_leftBarButtonItem
{
    UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    if ([UIDevice currentDevice].systemVersion.floatValue>=7.0)
    {
        spaceButtonItem.width = -10;
    }
    else
    {
        spaceButtonItem.width = 0;
    }
    
    if (_leftBarButtonItem)
    {
        [self setLeftBarButtonItems:@[spaceButtonItem, _leftBarButtonItem]];
    }
    else
    {
        [self setLeftBarButtonItems:@[spaceButtonItem]];
    }
}

- (void)setRightBarButtonItem:(UIBarButtonItem *)_rightBarButtonItem
{
    UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    if ([UIDevice currentDevice].systemVersion.floatValue>=7.0)
    {
        spaceButtonItem.width = -10;
    }
    else
    {
        spaceButtonItem.width = 0;
    }
    
    if (_rightBarButtonItem)
    {
        [self setRightBarButtonItems:@[spaceButtonItem, _rightBarButtonItem]];
    }
    else
    {
        [self setRightBarButtonItems:@[spaceButtonItem]];
    }
}

@end
